package rmi.eventing.types;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import rmi.eventing.types.AuctionEvent.Type;
/**
 * 
 *      USER_SESSIONTIME_MIN USER_SESSIONTIME_MAX USER_SESSIONTIME_AVG BID_PRICE_MAX
 *		BID_COUNTER_PER_MINUTE AUCTION_TIME_AVG AUCTION_SUCCESS_RATIO		
 *		Events
 */
public class StatisticEvent extends Event {
	private double value=0;
	public StatisticEvent(double value){
		super();
		ID = "AN"+idCounter;
		this.value=value;
	}
	public enum Type{
		USER_SESSIONTIME_MIN("USER_SESSIONTIME_MIN"), 
		USER_SESSIONTIME_MAX("USER_SESSIONTIME_MAX"),
		USER_SESSIONTIME_AVG("USER_SESSIONTIME_AVG"),
		BID_PRICE_MAX("BID_PRICE_MAX"),
		BID_COUNTER_PER_MINUTE("BID_COUNTER_PER_MINUTE"),
		AUCTION_TIME_AVG("AUCTION_TIME_AVG"),
		AUCTION_SUCCESS_RATIO("AUCTION_SUCCESS_RATIO");
		
		
		private String type;
		Type(String type){
			this.type = type;
		}
		public String getValue()
		{      
		      return type ;
		}
	}
	public void setType (Type type){
		this.type=type.getValue();
	}
	public String toString(){
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z");
		String date = dateFormat.format(timestamp);
		 DecimalFormat df = new DecimalFormat("0");
		
		if (type.equals("USER_SESSIONTIME_MIN")){
			return "USER_SESSIONTIME_MIN: "+date+" - minimum session time is "+df.format(value)+" seconds";
		}
		if (type.equals("USER_SESSIONTIME_MAX")){
			return "USER_SESSIONTIME_MAX: "+date+" - maximum session time is "+df.format(value)+" seconds";
					
		}
		if (type.equals("USER_SESSIONTIME_AVG")){
			return "USER_SESSIONTIME_AVG: "+date+" - average session time is "+df.format(value)+" seconds";
			
		}
		if (type.equals("BID_PRICE_MAX")){
			return "BID_PRICE_MAX : "+date+" - maximum bid price seen so far is "+value;
		}
		if (type.equals("BID_COUNTER_PER_MINUTE")){
			//round to 3 decimal places
			df = new DecimalFormat("0.000");
			return "BID_COUNTER_PER_MINUTE : "+date+" - current bids per minute is "+df.format(value);
		}
		if (type.equals("AUCTION_SUCCESS_RATIO")){
			df = new DecimalFormat("0.00");
			return "AUCTION_SUCCESS_RATIO : "+date+" - current auction success ratio is "+df.format(value);
		}
		if (type.equals("AUCTION_TIME_AVG")){
			return "AUCTION_TIME_AVG : "+date+" -  average auction time is "+df.format(value)+ " seconds";
		}

		
		return "STATISTIC_EVENT: No type set"; 
	}
}
